package com.lovo.roomProject.system.dao.impl;

import com.lovo.roomProject.dao.BaseDAO;
import com.lovo.roomProject.pojo.SystemDO;
import com.lovo.roomProject.system.dao.LoginDAO;

import java.sql.SQLException;

public class LoginDAOImpl extends BaseDAO implements LoginDAO {

    @Override
    public SystemDO LoginJudge(String userName, String password) {
        this.getConnection();
        SystemDO systemDO =new SystemDO();
        String sql = "SELECT * FROM  t_user WHERE u_account = ? AND u_password = ?";
        try {
            statement = con.prepareStatement(sql);
            statement.setObject(1, userName);
            statement.setObject(2, password);
            rs = statement.executeQuery();
            while (rs.next()) {
                systemDO =new SystemDO();
                systemDO.setId(rs.getInt("u_id"));
                systemDO.setAccount(rs.getString("u_account"));
                systemDO.setPassword(rs.getString("u_password"));
                systemDO.setName(rs.getString("u_name"));
                systemDO.setLevel(rs.getString("u_level"));
            }
            System.out.println("");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            close(con, statement);
        }
        return systemDO;
    }
}
